package com.xyzyzglxt.web.controller.volunteer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xyzyzglxt.common.core.domain.entity.SysVolunteersTime;
import com.xyzyzglxt.common.utils.poi.ExcelUtil;
import com.xyzyzglxt.system.service.ISysUserService;
import com.xyzyzglxt.system.service.ISysVolunteersTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xyzyzglxt.common.annotation.Log;
import com.xyzyzglxt.common.core.controller.BaseController;
import com.xyzyzglxt.common.core.domain.AjaxResult;
import com.xyzyzglxt.common.enums.BusinessType;
import com.xyzyzglxt.common.core.page.TableDataInfo;

/**
 * 自愿总时长Controller
 *
 * @author xyzyzglxt
 * @date 2022-03-02
 */
@Api(tags = "服务时长管理")
@RestController
@RequestMapping("/volunteer/time")
public class SysVolunteersTimeController extends BaseController
{
    @Autowired
    private ISysVolunteersTimeService sysVolunteersTimeService;


    /**
     * 查询自愿总时长列表
     */
    @ApiOperation("询自愿总时长列表")
    @PreAuthorize("@ss.hasPermi('volunteer:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVolunteersTime sysVolunteersTime)
    {
        startPage();
        List<SysVolunteersTime> list = sysVolunteersTimeService.selectSysVolunteersTimeList(sysVolunteersTime);
        return getDataTable(list);
    }

    /**
     * 导出自愿总时长列表
     */
    @ApiOperation("导出自愿总时长列表")
    @PreAuthorize("@ss.hasPermi('volunteer:time:export')")
    @Log(title = "自愿总时长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVolunteersTime sysVolunteersTime)
    {
        List<SysVolunteersTime> list = sysVolunteersTimeService.selectSysVolunteersTimeList(sysVolunteersTime);
        ExcelUtil<SysVolunteersTime> util = new ExcelUtil<SysVolunteersTime>(SysVolunteersTime.class);
        util.exportExcel(response, list, "自愿总时长数据");
    }

    /**
     * 获取自愿总时长详细信息
     */
    @ApiOperation("获取自愿总时长详细信息")
    @PreAuthorize("@ss.hasPermi('volunteer:time:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(sysVolunteersTimeService.selectSysVolunteersTimeByUserId(userId));
    }

    /**
     * 新增自愿总时长
     */
    @ApiOperation("新增自愿总时长")
    @PreAuthorize("@ss.hasPermi('volunteer:time:add')")
    @Log(title = "自愿总时长", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVolunteersTime sysVolunteersTime)
    {
        return toAjax(sysVolunteersTimeService.insertSysVolunteersTime(sysVolunteersTime));
    }

    /**
     * 修改自愿总时长
     */
    @ApiOperation("修改自愿总时长")
    @PreAuthorize("@ss.hasPermi('volunteer:time:edit')")
    @Log(title = "自愿总时长", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVolunteersTime sysVolunteersTime)
    {
        return toAjax(sysVolunteersTimeService.updateSysVolunteersTime(sysVolunteersTime));
    }

    /**
     * 删除自愿总时长
     */
    @ApiOperation("删除自愿总时长")
    @PreAuthorize("@ss.hasPermi('volunteer:time:remove')")
    @Log(title = "自愿总时长", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysVolunteersTimeService.deleteSysVolunteersTimeByUserIds(userIds));
    }
}

